<?php

declare(strict_types=1);

namespace WanZ\App\User\Action;

use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\RequestMapping;
use WanZ\App\User\Logic\UserLogic;
use MoChat\Framework\Action\AbstractAction;
use MoChat\Framework\Request\ValidateSceneTrait;
use MoChat\Framework\Constants\ErrorCode;
use MoChat\Framework\Exception\CommonException;

/**
 * 当前用户信息
 * @Controller
 */
class Show extends AbstractAction
{
    use ValidateSceneTrait;

    /**
     * @Inject
     * @var UserLogic
     */
    private $userLogic;
        
    /**
     * @RequestMapping(path="/user/info/get", methods="GET")
     * @return array 返回数组
     */
    public function handle(): array
    {     
        ## 参数验证
        $this->validated($this->request->all());
                  
        ## 请求参数
        $userId = (int) $this->request->input('u_id');
        $companyId = (int) $this->request->input('company_id');
        $groupId = (int) $this->request->input('group_id', 0);

        $isHiddenPhone = 0;
        if (isset($this->request->header('user-agent')[0]) 
            && getUserAgent($this->request->header('user-agent')[0], 'AliApp')) {
            $isHiddenPhone = 1;
        }

		return $this->userLogic->getUserInfoById($userId, $companyId, $isHiddenPhone, $groupId);
    }

    /**
     * 验证规则.
     *
     * @return array 响应数据
     */
    protected function rules(): array
    {
        return [
            'u_id' => 'required|integer|min:1|bail',
            'company_id' => 'required|integer|min:1|bail',
            'group_id' => 'integer|min:1|bail',
        ];
    }

    /**
     * 验证错误提示.
     * @return array 响应数据
     */
    protected function messages(): array
    {
        return [
            'u_id.required' => '用户ID 必填',
            'u_id.integer' => '用户ID 必需为整数',
            'u_id.min' => '用户ID 值必须大于1',   
            'company_id.required' => '公司ID 必填',
            'company_id.integer' => '公司ID 必需为整数',
            'company_id.min' => '公司ID 值必须大于1',                 
            'group_id.integer' => '分组ID 必需为整数',
            'group_id.min' => '分组ID 值必须大于1',  
        ];
    }
}